<template>
  <header class="header">
    <h1>todos</h1>
    <input
      id="toggle-all"
      class="toggle-all"
      type="checkbox"
      v-model="$store.state.isShow"
      @click="$store.commit('allShow',!$store.state.isShow)"
    />
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      v-model="message"
      @keydown.enter="keydownFn"
    />
  </header>
</template>

<script>
import {mapState} from 'vuex'
export default {
  data() {
    return {
      message: "",
    };
  },
  methods: {
    keydownFn() {
      if (this.message.trim() === "") {
        alert("请输入内容");
      } else {
        this.$store.commit("addTask", this.message);
        this.message = "";
      }
    },
  },
  computed: {
    ...mapState(['list']),
 
  },
}
</script>
